package com.example.javaeekeshe.mapper;

import com.example.javaeekeshe.pojo.AccountBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface AccountMapper {
    /**
     * 查找用户名密码是否正确
     * @param userName 用户名
     * @param password 加密后的密码
     * @return 用户信息
     */
    @Select("select * from account where username = #{userName} and password = #{password} limit 1")
    public AccountBean existByAccount(String userName, String password);

    /**
     * 判断用户是否存在
     * @param userName 用户名
     * @return 1存在   0不存在
     */
    @Select("select 1 from account where username= #{userName}")
    public Integer existByUsername(String userName);

    /**
     * 加入用户
     * @param account
     */
    @Insert("insert into account (username,password,name) values(#{username},#{password},#{name})")
    public void insertUser(AccountBean account);

    @Insert("INSERT INTO `account` (`id`, `username`, `password`, `name`, `sex`, `leave`) VALUES (null, #{username}, #{password}, null, null, 1)")
    public void insertAdmin(AccountBean accountBean);


    @Update("UPDATE account SET password = #{password} WHERE username=#{username}")
    public void Update(AccountBean accountBean);

    @Update("UPDATE account SET name = #{name} ,sex=#{sex} WHERE username=#{username}")
    public void rename(AccountBean accountBean);
}
